package com.egao.orderB.service.impl;

import com.egao.common.core.damon.results.PageResult2;
import com.egao.common.core.web.JsonResult;
import com.egao.common.system.entity.User;
import com.egao.orderB.biz.InvoiceNameBiz;
import com.egao.orderB.entity.InvoiceName;
import com.egao.orderB.service.InvoiceNameService;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

//import com.egao.orderB.mapper.InvoiceNameMapper;
//import javax.transaction.Transactional;

/**
 * 开票抬头服务实现类
 * @author : Doman
 * @date : 2020-10-09 11:21:15
 * @version ：1.0
 */
@Service
public class InvoiceNameServiceImpl /*extends ServiceImpl<InvoiceNameMapper, InvoiceName> */implements InvoiceNameService {

	@Autowired
	private InvoiceNameBiz invoiceNameBiz;

    /**
    @Override
    public PageResult<InvoiceName> listPage(PageParam<InvoiceName> page) {
        List<InvoiceName> records = baseMapper.listPage(page);
        return new PageResult<>(records, page.getTotal());
    }

    @Override
    public List<InvoiceName> listAll(Map<String, Object> page) {
        return baseMapper.listAll(page);
    } */

    @Override
    public JsonResult list(PageResult2<T> page, InvoiceName invoiceName, User loginUser)  throws Exception{
        return invoiceNameBiz.list(page,invoiceName,loginUser);
    }

    @Override
    public JsonResult list(InvoiceName invoiceName, User loginUser) {
        List<InvoiceName> list = invoiceNameBiz.list(invoiceName,loginUser);
        for(InvoiceName f: list) {
            if(f.getPinyin()==null || f.getPinyin().equals(""))
                invoiceNameBiz.update(f,loginUser);
        }
        return JsonResult.ok().setData(invoiceNameBiz.list(invoiceName,loginUser));
    }

    @Override
    public JsonResult getById(InvoiceName invoiceName) {
        return JsonResult.ok().setData(invoiceNameBiz.getById(invoiceName));
    }

    @Override
    public JsonResult save(InvoiceName invoiceName, User loginUser) {
        if (invoiceNameBiz.save(invoiceName, loginUser)) {
            return JsonResult.ok("添加成功");
        }
        return JsonResult.error("添加失败");
    }

    @Override
    public JsonResult update(InvoiceName invoiceName, User loginUser) {
        if (invoiceNameBiz.update(invoiceName, loginUser)) {
            return JsonResult.ok("修改成功");
        }
        return JsonResult.error("修改失败");
    }

    @Override
    public JsonResult updateState(InvoiceName invoiceName, User loginUser) {
        if (invoiceNameBiz.updateState(invoiceName, loginUser)) {
            return JsonResult.ok("修改成功");
        }
        return JsonResult.error("修改失败");
    }

    @Override
    public JsonResult remove(InvoiceName invoiceName, User loginUser) {
        if (invoiceNameBiz.remove(invoiceName, loginUser)) {
            return JsonResult.ok("删除成功");
        }
        return JsonResult.error("删除失败");
    }

}
